home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / prgtools / euphor13.zip / EPRINT.EX < prev    next >
Text File  |  1995-02-11  |  5KB  |  189 lines

  1.         ------------------------------
  2.         -- Print a Euphoria program --
  3.         ------------------------------
  4. -- This works with HP PCL printers.
  5. -- You can change control codes (bold, italics etc) for other printers.
  6. -- If you have a color printer you can choose colors,
  7. -- otherwise you will simply get keywords in bold, comments in italics.
  8. -- You can print non-Euphoria files too.
  9.  
  10. -- usage: eprint filename
  11.  
  12.  
  13. constant TRUE = 1, FALSE = 0
  14.  
  15. ---- some parameters you can adjust for your printer --------------------------
  16. constant NCOLUMNS = 2              -- 1 or 2
  17. constant CONDENSED = TRUE          -- TRUE or FALSE
  18. constant PAGE_LENGTH = 59*NCOLUMNS -- (upper bound) 118 for condensed
  19. constant COLOR_PRINTER = FALSE     -- TRUE (HP550C) or FALSE
  20. integer syntax
  21. syntax = TRUE                      -- to highlight syntax in .e/.ex/.pro files
  22. -------------------------------------------------------------------------------
  23.  
  24. constant ESC = 27
  25.  
  26. constant hp550c = {"2", "8", "1", "12", "4", "10", "1", "1"}
  27.  
  28. integer printer
  29.  
  30. procedure bold_on()
  31.     puts(printer, ESC & "(s3B")
  32. end procedure
  33.  
  34. procedure bold_off()
  35.     puts(printer, ESC & "(s0B")
  36. end procedure
  37.  
  38. procedure italics_on()
  39.     puts(printer, ESC & "(s1S")
  40. end procedure
  41.  
  42. procedure italics_off()
  43.     puts(printer, ESC & "(s0S")
  44. end procedure
  45.  
  46. procedure second_column()
  47.     puts(printer, ESC & "&a80C")
  48. end procedure
  49.  
  50. procedure form_feed()
  51.     puts(printer, 12)
  52. end procedure
  53.  
  54. procedure reset()
  55.     puts(printer, ESC & 'E')   -- reset
  56. end procedure
  57.  
  58. procedure color()
  59.     puts(printer, ESC & "*r-4U")  -- CYMK
  60. end procedure
  61.  
  62. procedure small()
  63.     puts(printer, ESC & "(s20H")    -- Print Pitch (width)
  64.     puts(printer, ESC & "(s8V")     -- Point Size (height)
  65.     puts(printer, ESC & "&l4C")     -- vertical motion
  66. end procedure
  67.  
  68. -- symbols needed by syncolor.e:
  69. global integer SCREEN
  70. global constant  NORMAL_COLOR = 8,
  71.         COMMENT_COLOR = 4,
  72.         KEYWORD_COLOR = 1,
  73.         BUILTIN_COLOR = 5,
  74.          STRING_COLOR = 6
  75.  
  76. global constant BRACKET_COLOR = {NORMAL_COLOR}
  77.  
  78. global procedure text_color(integer color)
  79. -- this overrides the graphics.e procedure for screen color
  80. -- that is used by syncolor.e
  81.     sequence color_code
  82.  
  83.     if not syntax then
  84.     return
  85.     end if
  86.  
  87.     if COLOR_PRINTER then
  88.     color_code = hp550c[color]
  89.     puts(printer, ESC & "*v" & color_code & "S")
  90.     else
  91.     -- normal mono printer
  92.     if color = KEYWORD_COLOR then
  93.         italics_off()
  94.         bold_on()
  95.     elsif color = COMMENT_COLOR then
  96.         bold_off()
  97.         italics_on()
  98.     else
  99.         italics_off()
  100.         bold_off()
  101.     end if
  102.     end if
  103. end procedure
  104.  
  105. include syncolor.e
  106.  
  107. procedure try_colors()
  108. -- display colors on hp550c
  109.     for i = '0' to '6' do
  110.     for j = '0' to '9' do
  111.         puts(printer, ESC & "*v" & i & j & "S")
  112.         printf(printer, "%s:", {i&j})
  113.         puts(printer, "Testing Colors ...\n")
  114.     end for
  115.     end for
  116. end procedure
  117.  
  118. procedure eprint()
  119.     integer efile
  120.     sequence command, matchname
  121.     object line
  122.     sequence buffer
  123.     integer base_line
  124.  
  125.     command = command_line()
  126.     if length(command) != 3 then
  127.     puts(1, "usage: eprint filename\n")
  128.     return
  129.     end if
  130.     efile = open(command[3], "r")
  131.     if efile = -1 then
  132.     puts(1, "couldn't open " & command[3] & '\n')
  133.     return
  134.     end if
  135.     matchname = command[3] & '&'
  136.     if not match(".e&", matchname) and
  137.        not match(".ex&", matchname) and
  138.        not match(".pro&", matchname) then
  139.     syntax = FALSE
  140.     end if
  141.     printer = open("PRN", "w")
  142.     if printer = -1 then
  143.     puts(1, "Can't open printer\n")
  144.     return
  145.     end if
  146.     SCREEN = printer -- SCREEN is needed by syncolor
  147.     init_class()
  148.     reset()
  149.     if COLOR_PRINTER then
  150.     color()
  151.     end if
  152.     if CONDENSED then
  153.     small()
  154.     end if
  155.  
  156.     -- read in whole file
  157.     buffer = {}
  158.     while 1 do
  159.     line = gets(efile)
  160.     if atom(line) then
  161.         exit
  162.     end if
  163.     if line[length(line)] != '\n' then
  164.         line = line & '\n' -- need end marker
  165.     end if
  166.     buffer = append(buffer, line)
  167.     end while
  168.     base_line = 1
  169.     while base_line <= length(buffer) do
  170.     for i = base_line to base_line + PAGE_LENGTH - 1 do
  171.         if i <= length(buffer) then
  172.         DisplayColorLine(buffer[i])
  173.         if NCOLUMNS = 2 and i + PAGE_LENGTH <= length(buffer) then
  174.             second_column()
  175.             DisplayColorLine(buffer[i + PAGE_LENGTH])
  176.         end if
  177.         puts(printer, '\n')
  178.         end if
  179.     end for
  180.     base_line = base_line + PAGE_LENGTH * NCOLUMNS
  181.     form_feed()
  182.     end while
  183.     close(efile)
  184.     close(printer)
  185. end procedure
  186.  
  187. eprint()
  188.  
  189.